Skip to content

🧪 Add logic tests for preserved function definitions by AST#11

Merged
bashandbone merged 5 commits intomainfrom
add-has-preserved-definition-tests-434298203320126471
Mar 13, 2026
Merged

🧪 Add logic tests for preserved function definitions by AST#11
bashandbone merged 5 commits intomainfrom
add-has-preserved-definition-tests-434298203320126471

Conversation

@bashandbone
Copy link
Contributor

🎯 What: The gap in testing for _has_preserved_definition in CodeGenerator was addressed. Previously, it lacked test cases to verify that ast.FunctionDef, ast.AsyncFunctionDef, ast.Assign, and ast.AnnAssign were correctly identified within the preserved sections of generated __init__.py code. Additionally, tests/fixtures/sample_type_aliases.py was fixed to properly reflect pre-python3.12 syntax.
📊 Coverage: Covered all logical branches of _has_preserved_definition (functions, async functions, assignments, annotated assignments, syntax errors, empty strings).
Result: Increased test suite reliability and guaranteed 100% coverage on exportify/export_manager/generator.py line 372.


PR created automatically by Jules for task 434298203320126471 started by @bashandbone

Adds comprehensive test coverage for `CodeGenerator._has_preserved_definition`
in `src/exportify/export_manager/generator.py`, validating its ability to detect
regular and async function definitions, as well as regular and annotated assignments.
Also fixes `sample_type_aliases.py` to use correct pre-3.12 syntax, passing the
type alias detection tests.

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 13, 2026 02:29
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds missing unit coverage for CodeGenerator._has_preserved_definition to ensure preserved sections in generated __init__.py are correctly detected via AST parsing, and updates a type-alias fixture to match the intended “pre-3.12” alias style.

Changes:

  • Add tests covering _has_preserved_definition for FunctionDef, AsyncFunctionDef, Assign, AnnAssign, syntax errors, and empty input.
  • Update tests/fixtures/sample_type_aliases.py to use TypeAlias assignment syntax for “pre-3.12” examples.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
tests/test_generator.py Adds targeted tests for _has_preserved_definition logic branches.
tests/fixtures/sample_type_aliases.py Fixes the “pre-3.12” type-alias examples to use TypeAlias assignment style.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +23
test_file_path: FilePath | None = None

from typing import TypeAlias

Comment on lines +1006 to +1008
import pytest
from exportify.export_manager.generator import CodeGenerator

Comment on lines +1008 to +1033

def test_has_preserved_definition_function(generator: CodeGenerator):
"""Test _has_preserved_definition detects a function."""
assert generator._has_preserved_definition("def my_func(): pass", "my_func")
assert not generator._has_preserved_definition("def my_func(): pass", "other_func")

def test_has_preserved_definition_async_function(generator: CodeGenerator):
"""Test _has_preserved_definition detects an async function."""
assert generator._has_preserved_definition("async def my_async_func(): pass", "my_async_func")

def test_has_preserved_definition_assign(generator: CodeGenerator):
"""Test _has_preserved_definition detects a variable assignment."""
assert generator._has_preserved_definition("my_var = 1", "my_var")
assert generator._has_preserved_definition("my_var = my_other_var = 1", "my_var")
assert generator._has_preserved_definition("my_var = my_other_var = 1", "my_other_var")

def test_has_preserved_definition_ann_assign(generator: CodeGenerator):
"""Test _has_preserved_definition detects an annotated assignment."""
assert generator._has_preserved_definition("my_var: int = 1", "my_var")
assert not generator._has_preserved_definition("my_var: int = 1", "other_var")

def test_has_preserved_definition_syntax_error(generator: CodeGenerator):
"""Test _has_preserved_definition handles syntax errors gracefully."""
# Invalid syntax will be suppressed, resulting in False
assert not generator._has_preserved_definition("def my_func(:: pass", "my_func")

Add `# ruff: noqa: UP040` to `tests/fixtures/sample_type_aliases.py`
to prevent the linter from enforcing the modern `type X = Y` syntax,
as this file explicitly tests pre-Python 3.12 type alias parsing
backward compatibility.

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
type ErrorMessage = str
type ConfigDict = dict[str, str | int | bool | list[str]]
type NamePair = tuple[str, str]
FilePath: TypeAlias = str | Path
bashandbone and others added 3 commits March 12, 2026 23:34
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
Removed unused import of pytest from test_generator.py

Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
…320126471

Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
@bashandbone bashandbone merged commit 76f1711 into main Mar 13, 2026
5 of 9 checks passed
@bashandbone bashandbone deleted the add-has-preserved-definition-tests-434298203320126471 branch March 13, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants